import { observable, action, autorun, toJS } from 'mobx';
import { WeaLocaleProvider } from 'ecCom';
import {WeaForm, WeaTableNew} from 'comsMobx'
import {message, Button } from "antd";
import * as Apis from '../../apis/info';
import { feedbackDialogStore } from '../dialog/feedbackDialogStore';

const {TableStore} = WeaTableNew;
const getLabel = WeaLocaleProvider.getLabel;
export default class infoFeedbackStore {

    @observable feedbackDialogStore = new feedbackDialogStore(this);

    @observable tableStore = new TableStore();
    @observable isRight = false;        //判断是否有权限
    @observable loadingSpin = true;     //全局loading

    /** 高级查询store */
    @observable searchForm = new WeaForm();
    @observable showSearchAd = false;   //高级搜索显隐
    searchCondition = [];
    constructor(props) {
    }

    @observable status = {
    }

    setState = (params = {}) => {
        Object.keys(params).forEach(o => {
            this.status[o] = params[o];
        })
        return this;
    }

    //得到信息反馈List
    @action
    getInfoFeedbackList = (params = {}) => {
        this.loadingSpin = true;
        this.searchForm = new WeaForm();
        this.searchCondition = [];
        Apis.getInfoFeedbackList().then(data => {
            this.loadingSpin = false;
            this.isRight = data.isRight;
            if (!this.isRight) {
                return;
            }
            this.tableStore.getDatas(data.sessionkey, 1);
            this.searchCondition = data.infoConditionGroup;
            this.searchForm && !this.searchForm.isFormInit && this.searchForm.initFormFields(data.infoConditionGroup);
        })
    }

    @action
    doSearch = (params = {}) => {
        this.status.loading = true;
        //获取表单的参数值
        const searchParamsAd = this.searchForm.getFormParams();
        const newParams = {...searchParamsAd };
        Apis.getInfoFeedbackList(newParams).then(data => {
            this.tableStore = new TableStore();
            this.tableStore.getDatas(data.sessionkey, 1);
            this.status.loading = false;
        })
    }

    setShowSearchAd = (bool) => {
        this.showSearchAd = bool;
    }

    appendFormFields(value) {
        this.searchForm.updateFields(value, false);
    }

    clearFormFields = () => {
        this.searchForm.resetConditionValue();      //清除查询条件值
    }
}